package day11;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Test;
public class JDBCUtil {
	// 静态代码块，在类加载到内存的时候就执行，而且只执行一次
		// 保证这个驱动在运行过程中只加载一次
		static {
			try {
				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		}

		public static Connection getConnection() {
			Connection connection = null;
			try {
				connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java1912?useUnicode=true&characterEncoding=UTF-8", "root", "Root");
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return connection;
		}
		
		// Ctrl+Shift+O
		public static void close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) {
			if (resultSet != null) {
				try {
					resultSet.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (preparedStatement != null) {
				try {
					preparedStatement.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		@Test
		public void test12() {
			 int[] array = {52, 20, 56, 14,  15, 555, 45};
             for (int i = 1; i < array.length; i++) {
                    for (int j = 0; j < array.length -i; j++) {
                           if (array[j] < array[j + 1]) {
                                 int temp = array[j];
                                 array[j] = array[j + 1];
                                 array[j + 1] = temp;
                           }
                    }
                    
             }
             for (int j = 0; j < array.length; j++) {
                    System.out.println(array[j]);
             }
		}

}
